<script type="text/javascript">
	$(function(){
	$('.deleteForum').click(function(){
		con = confirm("กรุณายืนยันการลบข้อมูล");
		
		if(con){
			var id = $(this).attr("id");
			var isMain = $(this).attr("isMain");
			$.ajax({
				url:$(this).attr("href")
				,type:'post'
				,dataType : 'json'
				,data:{id:id,isMain:isMain}
				,success:function(data){
					if(isMain=="Y"){
						window.location.href=baseUrl+"forum/";
					}else{
						window.location.reload();
					} 
				}
			})
		}
		return false;
		})
	})
</script>
<div class="boxMessage first">
<h2 class="text-primary"><?php echo $dataList->title?></h2>
<small>post date: <?php echo $dataList->createOn?></small>
<p><?php echo stripslashes($dataList->message)?></p>
<p>post by <?php echo $dataList->postname?></p>
<?
	if($dataList->image!=""){
	?>
		<strong>ภาพแนบ</strong><br />
		<img style="max-width: 100%;margin:0px auto;text-align:center;display:block;" src="<?php echo site_url()."file_upload/". $dataList->image?>" />
	<?
	}
?>
</div>
<?
if($canEdit && $this->util->canAction($dataList->postby)){
?>
<a class="btn btn-primary" href="<?php echo $current?>edit/<?php echo $dataList->fID?>"><i class="fa fa-edit"></i>edit this post</a>
<?
}
?>
<?
if($canDelete && $this->util->canAction($dataList->postby)){
?>
<a class="btn btn-primary deleteForum" isMain="<?php echo $dataList->isMain?>" id="<?php echo $dataList->fID?>" href="<?php echo $current?>deleteForum/"><i class="fa fa-edit"></i>Delete this post</a>
<?
}
?>
<?
if(isset($dataList->ListDetail)){
	?>
	<h2>Reply</h2>
	
	<div class="row">
	<?
	foreach($dataList->ListDetail as $in=>$val){
	?>
		<div class="col-sm-12" >
			<div class="boxMessage clearfix">
			<p><?php echo stripslashes($val->message)?></p>
			<small>reply date: <?php echo $val->createOn?></small>
			<small>reply by : <?php echo $val->postname?></small>
			<?if($dataList->image!=""){
	?>
		<br />
		<strong>ภาพแนบ</strong><br />
		<img style="max-width: 100%;margin:0px auto;text-align:center;display:block;margin-bottom:10px" src="<?php echo site_url()."file_upload/". $val->image?>" />
	<?
	}?>
			<div style="float: right">
			<?
if($canEdit && $this->util->canAction($val->postby)){
?>
<a class="" style="color:red" href="<?php echo $current?>edit/<?php echo $val->fID?>"><i class="fa fa-edit"></i>edit this reply</a>
<?
}
?>
<?
if($canDelete && $this->util->canAction($val->postby)){
?>
 | <a class="deleteForum" style="color:red" isMain="<?php echo $val->isMain?>" id="<?php echo $val->fID?>" href="<?php echo $current?>deleteForum/"><i class="fa fa-edit"></i>Delete this reply</a>
<?
}
?>
</div>
</div>
		</div>
		
	<?
	}
	?>
	</div>
	<?
}
?>
<hr />
<h2>Reply Message</h2>
<form id="myForm" action="<?php echo $current?>replyforum" class="form-horizontal" role="form">

	<?
	
	echo $genhtml->getTextArea("","message",true);
	echo $genhtml->getHidden("parent","fID");
	echo $genhtml->getHidden("title","title");
	echo '<div id="containImage" style="padding:0px">';
	
	echo '<input type="hidden" id="image" name="image" value="'.$dataList->image.'" />';
	echo '</div>';
	echo $genhtml->getUpload();
	echo $genhtml -> getButton("Submit", "UpdateData", "Post", "primary");
	?>
</form>
<script src="<?php echo $pjs?>vendor/jquery.ui.widget.js"></script>
<script src="<?php echo $pjs?>jquery.iframe-transport.js"></script>

<script src="<?php echo $pjs?>jquery.fileupload.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="<?php echo $pcss?>jquery.fileupload.css" rel="stylesheet">

<script>
/*jslint unparam: true */
/*global window, $ */
$(function () {
    'use strict';
    // Change this to the location of your server-side upload handler:
    var url = '<?php echo $current.'uploadImage'?>';
    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
        	if(data.result.flag){
        		var size = $('#containImage').find('img').size();
        		if(size==0){
        			$('#containImage').append('<img src="" />');
        		}
        		$('#image').val(data.result.message);
        		$('#containImage img').attr("src",'<?php echo site_url() ?>file_upload/'+data.result.message);
        	}else{
        		alert("error on upload")
        	}
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .progress-bar').css(
                'width',
                progress + '%'
            );
        }
    }).prop('disabled', !$.support.fileInput)
        .parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>
<script type="text/javascript">
	$(document).ready(function() {
		initNormalForm(function(data){
			window.location.reload();
		})
	})
</script>
